<template>
  <div class="hello">
    <!--  用户查询  -->
    <el-form :inline="true"  class="demo-form-inline" style="text-align: left">
      <el-form-item label="用户名">
        <el-input v-model="username" placeholder="请输入用户名" size="mini"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlePearch" size="mini" icon="el-icon-search">查询</el-button>
        <el-button @click="resetForm" size="mini" icon="el-icon-refresh">重置</el-button>
      </el-form-item>
    </el-form>

    <!--按钮-->
    <el-row style="text-align: left;margin-bottom:20px">
      <el-button type="danger"  size="mini"  icon="el-icon-delete"plain>批量删除</el-button>
      <el-button type="warning" size="mini" icon="el-icon-download" plain>导入</el-button>
      <el-button type="warning" size="mini" icon="el-icon-upload2" plain>导出</el-button>
      <el-button type="primary" size="mini" icon="el-icon-plus" plain @click="handleAdd">添加</el-button>
    </el-row>

    <!--  表格  -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      border
     >

      <el-table-column
        type="selection"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        prop="id"
        label="编号"
        width="150"
        align="center">

      </el-table-column>
      <el-table-column
        label="日期"
        width="200"
        align="center">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="200"
        align="center">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        show-overflow-tooltip
        width="1000"
        align="center">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            class="el-icon-edit"
            type="text"
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            class="el-icon-delete"
            size="mini"
            type="text"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <br>

    <!--  分页  -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      background
      layout="total, sizes, prev, pager, next, jumper"
      align="left"
      :total="totals">
    </el-pagination>

    <!-- 对话框   -->
    <el-dialog
      title="添加和修改"
      :visible.sync="dialogVisible"
      width="30%">
      <span>
          <el-form label-width="80px" :model="formData">
            <el-form-item label="日期" >
              <el-input v-model="formData.date"></el-input>
            </el-form-item>
            <el-form-item label="姓名" >
              <el-input v-model="formData.name"></el-input>
            </el-form-item>
            <el-form-item label="地址" >
              <el-input v-model="formData.address"></el-input>
            </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>


</template>

<script>
import {Row} from "element-ui";

//引入axios
import axios from "axios";

export default {
  data() {
    return {
      // 高级查询+分页查询
      tableData: [],
      totals:0,
      currentPage:1,
      pageSize:5,

      // 查询框
      username:"爽呀爽歪歪",

      // 添加和修改的相关数据
      formData:{
        date: '',
        name: '',
        address:''
      },   // 控制对话框
      dialogVisible:false
    }},

  methods: {
    // 高级查询+分页查询
    getData() {
      axios.post('/emp/list', {"currentPage":this.currentPage,"pageSize":this.pageSize}).then(res =>{
        this.tableData = res.data.data;
         this.totals = res.data.totals
      })
    },

    //  点击每页显示的条数发生的事情
    handleSizeChange(pageSize) {
     this.pageSize = pageSize; // 获取每页显示的条数
       this.getData(); // 获取数据
    },

    // 当前页
    handleCurrentChange(currentPage) {
      this.currentPage=currentPage;
      this.getData();
    },

    // 添加
    handleAdd(){
      this.dialogVisible=true; // 显示对话框
      this.formData={} // 清空表单里面的护具
    },

    // 修改
    handleEdit(index,row){
      this.formData = row; // 数据回显
      this.dialogVisible = true; // 显示对话框
    },

    // 删除
    handleDelete(index,row){},

    // 查询
    handlePearch(){
    },

    // 重置
    resetForm(){
      alert("你竟然还想重置，狗贼")
    }
  },

  // 页面加载显示的内容
  mounted() {
    this.getData();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
